package com.example.personal.controller;

import com.example.personal.entity.po.UserPO;
import com.example.personal.entity.vo.CommonResult;
import com.example.personal.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created on 2022/3/9.
 *
 * @author taodq
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public CommonResult insert(@Valid @RequestBody UserPO user) {
        return userService.insert(user);
    }

    @GetMapping("/select")
    public CommonResult<UserPO> select(Long currentPage, Long pageSize) {
        return userService.selectPage(currentPage, pageSize);
    }

    @DeleteMapping("/delete")
    public CommonResult delete(@RequestBody Long id) {
        return CommonResult.ok(userService.removeById(id));
    }

    @PutMapping("/update")
    public CommonResult update(@RequestBody UserPO user) {
        return userService.updateUserById(user);
    }
}
